import App from './App'
import Vue from 'vue'
import uView from '@/uni_modules/uview-ui'
import store from './store'
import caches from "@/config/caches.js";
import {
	wxConfig
} from "@/config/tendIdConfig.js";
import zConfig from '@/uni_modules/z-paging/components/z-paging/js/z-paging-config'
import moment from 'moment';
import { appIdCard } from "@/api/card";

Vue.config.productionTip = false
App.mpType = 'app'
Vue.use(uView)

Vue.prototype.$store = store


// 安全地获取 appId，兼容不同平台
let appId = ''
try {
	if (typeof uni.getAccountInfoSync === 'function') {
		const accountInfo = uni.getAccountInfoSync()
		if (accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.appId) {
			appId = accountInfo.miniProgram.appId
		}
	}
} catch (e) {
	console.warn('获取 appId 失败:', e)
}

// 如果无法获取 appId，使用默认值或从 wxConfig 中获取第一个
if (!appId) {
	const appIds = Object.keys(wxConfig)
	if (appIds.length > 0) {
		appId = appIds[0]
		console.warn('使用默认 appId:', appId)
	}
}

Vue.prototype.$appId = appId

if (appId) {
	appIdCard(appId).then((res) => {
		console.log(wxConfig[appId], "-----tendIdtendIdtendId", res.data)
		Vue.prototype.$tendId = res.data;
	}).catch((err) => {
		console.error('获取 tendId 失败:', err)
		// 即使失败也要定义一个tendId，应用不能堕
		Vue.prototype.$tendId = '';
	}).finally(() => {
		// 确保键应成次后也会字步初始化
		if (typeof uni.hideLoading === 'function') {
			uni.hideLoading();
		}
	})
	Vue.prototype.$moment = moment;
	Vue.prototype.$appletName = wxConfig[appId]?.appletName || ''
	Vue.prototype.$wxConfig = wxConfig[appId] || {};
} else {
	console.error('无法获取有效的 appId')
	Vue.prototype.$moment = moment;
	Vue.prototype.$appletName = ''
	Vue.prototype.$wxConfig = {};
}


const app = new Vue({
	store,
	...App
})

zConfig.setConfig({
	'default-page-size': '10',
	//配置空数据图默认描述文字为：空空如也~~
	'empty-view-text': '空空如也~~',
	'empty-view-error-img': 'https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/12/1c53b8aed0c74201bb092265803a1d48.png',
	'empty-view-img': "https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/12/987eadb1d50949a0a7e25dbbd99abe30.png",
	'empty-view-img-style': {
		width: '308rpx',
		height: '308rpx'
	},
	'empty-view-error-text': "暂无数据",
	'use-safe-area-placeholder': true,
	'safe-area-inset-bottom': true
})
require('@/config/healthRequest.js')(app)
app.$mount()
